//订单管理功能需要的store

import axios from 'axios'
import * as URL from '../../ajax/api'

const state = {
    orderList:[],
    oneOrder:[],
};

const actions = {
    getOrderList({commit}){    //获取订单列表
        return axios({
            url:URL.GetOrderData,
            type:'get'
        }).then(res=>{
            if (res.data.code===200){
                commit('orderData',res.data.orderData);
            }
            return res.data
        });
    },
    getOneOrder({commit},orderId){   //获得某个订单的信息
        state.orderList.filter(item=>{
            if (item.id===orderId){
                commit('oneOrderData',item);
            }
        })
    }
};

const mutations = {
    orderData(state,obj){
        state.orderList=obj;
    },
    oneOrderData(state,obj){
        state.oneOrder=obj;
    }
};

export default{
    state,
    actions,
    mutations
}